#pragma once
#include "RBTree.h"

namespace Lzc
{
	template<class K, class V>
	class MyMap
	{
		struct MapKfromT
		{
			const K& operator()(const pair<const K, V>& kv)
			{
				return kv.first;
			}
		};

	public:
		typedef typename RBTree<K, pair<const K, V>, MapKfromT>::Iterator iterator;
		typedef typename RBTree<K, pair<const K, V>, MapKfromT>::ConstIterator const_iterator;

		pair<iterator, bool> insert(const pair<const K, V>& kv)
		{
			return _t.Insert(kv);
		}

		V& operator[](const K& k)
		{
			iterator ret = _t.Insert({ k, V() }).first;
			return ret->second;
		}

		iterator find(const K& key)
		{
			return _t.Find(key);
		}

		const_iterator find(const K& key) const
		{
			return _t.Find(key);
		}

		iterator begin()
		{
			return _t.Begin();
		}

		iterator end()
		{
			return _t.End();
		}

		const_iterator begin() const
		{
			return _t.Begin();
		}

		const_iterator end() const
		{
			return _t.End();
		}

	private:
		RBTree<K, pair<const K, V>, MapKfromT> _t;
	};
}